#include <iostream>
#include <vector>
using namespace std;

int max_long_path(vector<vector<int>> &gh, int row, int col, vector<vector<int>> & rec)
{
        int R = gh.size() - 1;
        int L = gh[0].size() - 1;

        if(rec[row][col] != -1){
                return rec[row][col];
        }

        int ans = 1;
        if(row > 1 && gh[row][col] > gh[row - 1][col]){
                ans = max(ans, 1 + max_long_path(gh, row - 1, col, rec));
        }

        if(row < R && gh[row][col] > gh[row + 1][col]){
                ans = max(ans, 1 + max_long_path(gh, row + 1, col, rec));
        }

        if(col > 1 && gh[row][col] > gh[row][col - 1]){
                ans = max(ans, 1 + max_long_path(gh, row, col - 1, rec));
        }

        if(col < L && gh[row][col] > gh[row][col + 1]){
                ans = max(ans, 1 + max_long_path(gh, row, col + 1, rec));
        }

        return rec[row][col] = ans;

}

int main()
{
        int r, c;
        cin>>r>>c;
        vector<vector<int>> gh(r + 1, vector<int>(c + 1, 0));
        vector<vector<int>> recd(r + 1, vector<int>(c + 1, -1));
        for(int i = 1; i <= r; i++){
                for(int j = 1; j <= c; j++){
                        cin>>gh[i][j];
                }
        }

        int ans = INT32_MIN;
        for(int i = 1; i <= r; i++){
                for(int j = 1; j <= c; j++){
                        ans = max(ans, max_long_path(gh, i, j, recd));
                }
        }

        cout<<ans<<endl;
        return 0;
}